<template>
	<view class="content">
		<view class="bgColor">
			<image src="/static/examine/msgBg.png" mode=""></image>
		</view>
		<cusHeaderVue titleContent="消息详情" :showBack="true"></cusHeaderVue>
		<view class="contBox" :style="{paddingTop: `calc(${scrollerHeight} + 130rpx)`}">
			<view class="contTop">
				<view class="contTit">
					{{ messageData.templateContent || '消息详情' }}
				</view>
				<view v-if="hasStoreContent" class="contNum">
					门店数量<text>{{ storeList.length }}</text>
				</view>
			</view>
		</view>
		<view class="contBoxBig">
			<scroll-view scroll-y="true" :style="{height:swiperHeight}">
				<!-- 未跑动门店内容 -->
				<view v-if="hasStoreContent" class="listBox">
					<view class="listLi" v-for="(store, index) in storeList" :key="index">
						<view class="listLeft">
							<view class="listName">
								{{ store.name || store }}
							</view>
							<view v-if="store.consecutiveMissingDays" class="listTime">
								未跑动天数：<text>{{ store.consecutiveMissingDays }}</text>
							</view>
						</view>
					</view>
				</view>
				
				<!-- 普通消息内容 -->
				<view v-else class="paramsBox">
					<view class="paramsLi" v-for="(value, key) in messageData.templateParams" :key="key">
						<view class="paramLabel">{{ key }}</view>
						<view class="paramValue">{{ value }}</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script setup>
	import cusHeaderVue from '@/components/cus-header.vue';
	import {
		ref,
		onMounted,
		reactive,
		computed
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	
	const scrollerHeight = ref('');
	const swiperHeight = ref('');
	const messageData = ref({});
	
	// 计算属性：判断是否包含未跑动门店内容
	const hasStoreContent = computed(() => {
		return messageData.value.templateContent && messageData.value.templateContent.includes('未跑动门店');
	});
	
	// 计算属性：解析门店列表
	const storeList = computed(() => {
		if (!hasStoreContent.value || !messageData.value.jsonStr) return [];
		try {
			// 尝试解析jsonStr
			const parsed = typeof messageData.value.jsonStr === 'string' 
				? JSON.parse(messageData.value.jsonStr) 
				: messageData.value.jsonStr;
			return Array.isArray(parsed) ? parsed : [];
		} catch (error) {
			console.error('解析jsonStr失败', error);
			return [];
		}
	});
	
	onLoad(() => {
		getBarHeight();
		// 从本地存储获取消息数据
		const item = uni.getStorageSync('messageItem');
		if (item) {
			messageData.value = item;
		}
	})
	
	// 获取状态栏高度
	const getBarHeight = () => {
		uni.getSystemInfo({
			success: function(resu) {
				scrollerHeight.value = resu.statusBarHeight + 'px'
				// 计算滚动区域高度
				const query = uni.createSelectorQuery();
				query.select('.contBoxBig').boundingClientRect();
				query.exec(res => {
					swiperHeight.value = resu.windowHeight - res[0].top - resu.safeAreaInsets
						?.bottom || 0 - resu.statusBarHeight - 70 +
						'px';
				});
			}
		});
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		height: 100vh;
	}
	.bgColor{
		width: 750rpx;
		height: 740rpx;
		position: absolute;
		z-index: -1;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.contBox{
		width: 100%;
		padding: 22rpx;
		box-sizing: border-box;
		.contTop{
			padding: 0 24rpx;
			box-sizing: border-box;
			.contTit{
				font-weight: 500;
				font-size: 33.33rpx;
				color: #7C4D1D;
				margin-bottom: 15rpx;
			}
			.contNum{
				font-size: 24.36rpx;
				font-weight: 400;
				color: #222222;
				 text{
					 font-size: 32.05rpx;
					 font-weight: 400;
					 color: #F79F31;
					 margin-left: 9rpx;
				}
			}
		}
	}
	.contBoxBig{
		padding: 10rpx 22rpx;
		box-sizing: border-box;
		
		// 门店列表样式
		.listBox{
			.listLi{
				width: 100%;
				border-radius: 12.82rpx;
				background: #ffffff;
				padding: 35rpx 27rpx;
				box-sizing: border-box;
				margin-bottom: 19rpx;
				box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
				.listLeft{
					.listName{
						font-weight: 500;
						font-size: 33.33rpx;
						color: #1C2027;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						width: 650rpx;
						margin-bottom: 10rpx;
					}
					.listTime{
						font-size: 26.92rpx;
						font-weight: 400;
						color: #5A5964;
						text{
							font-weight: 700;
							font-size: 28.21rpx;
							color: #F79F31;
							margin: 0 6rpx;
						}
					}
				}
			}
		}
		
		// 参数列表样式
		.paramsBox{
			background: #ffffff;
			border-radius: 12.82rpx;
			padding: 25rpx;
			box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
			
			.paramsLi{
				padding: 20rpx 0;
				border-bottom: 1rpx solid #f0f0f0;
				display: flex;
				justify-content: space-between;
				align-items: flex-start;
				
				&:last-child {
					border-bottom: none;
				}
				
				.paramLabel{
					font-size: 28.21rpx;
					font-weight: 500;
					color: #5A5964;
					flex: 1;
					margin-right: 15rpx;
				}
				
				.paramValue{
					font-size: 28.21rpx;
					font-weight: 400;
					color: #1C2027;
					flex: 2;
					text-align: right;
					word-break: break-all;
					line-height: 42rpx;
				}
			}
		}
	}
</style>